package com.vlyman.rtn;

import com.vlyman.rtn.consts.BaseRtn;
import com.vlyman.rtn.consts.IBaseRtn;

/**
 * 类描述：
 *  接口返回信息构造
 *  @author chenjs
 *  @date 2018/9/19 20:45
 **/
public class RtnResult {

    private String rtnMsg;
    private int rtnCode;
    private Object data;

    public static RtnResult success() {
        return new RtnResult().setParams(BaseRtn.SUCCESS);
    }
    public static RtnResult error() {
        return new RtnResult().setParams(BaseRtn.ERROR);
    }
    public static RtnResult noData() {
        return new RtnResult().setParams(BaseRtn.EMPTY_RESULT);
    }
    public static RtnResult paramValidationError() {
        return new RtnResult().setParams(BaseRtn.PARAM_VALIDATION_ERROR);
    }
    public static RtnResult setRtn(IBaseRtn baseRtn) {
        return new RtnResult().setParams(baseRtn);
    }
    private RtnResult setParams(IBaseRtn baseRtn) {
        this.rtnMsg = baseRtn.getMsg();
        this.rtnCode = baseRtn.getCode();
        return this;
    }
    public Object getData() {
        return data;
    }
    public RtnResult setData(Object data) {
        this.data = data;
        return this;
    }

    public String getRtnMsg() {
        return rtnMsg;
    }

    public RtnResult setRtnMsg(String rtnMsg) {
        this.rtnMsg = rtnMsg;
        return this;
    }

    public int getRtnCode() {
        return rtnCode;
    }

    public RtnResult setRtnCode(int rtnCode) {
        this.rtnCode = rtnCode;
        return this;
    }
}
